<template>
  <div>
    <van-form >
      <van-field
        v-model="date.mobile"
        name="mobile"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="date.code"
        type="code"
        name="code"
        label="验证码"
        placeholder="验证码"
        :rules="[{ required: true, message: '请填写验证码' }]"
      />
      <div style="margin: 14px" >
        <van-button round block type="info" @click="YanZheng(username)">发送验证码</van-button>
      </div>
      <div style="margin: 14px">
        <van-button round block type="info" @click="denglu">登录</van-button>
      </div>
      
    </van-form>
  </div>
</template>

<script>
import { Toast } from 'vant'
import { YanZhengMaApi,DengLuApi } from '../api/user'
export default {
  data () {
    return {
      date:{
        mobile: '',
        code: ''
      }
    }
  },
  methods:{
   async YanZheng(username){
    const res= await YanZhengMaApi(username)
    console.log(res)
    },
   async denglu(){
    const res= await  DengLuApi(this.date)
     console.log(res)
     localStorage.setItem('token', res.data.token)
     Toast('登录成功')
    this.$router.push('/ShouYe')
    }
  }
}
</script>

<style>
</style>
